# @shuaige : 陈世玉
# @name :test1.py
# @time :2025/1/2 11:10
import requests
from lxml import etree

for i in range(300,500):

    url = 'https://www.dongchedi.com/auto/params-carIds-x-' + str(i)
    headers = {
        'pragma': 'no-cache',
        'accept-language': 'zh-CN,zh;q=0.9',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
        'accept': '*/*',
        'cache-control': 'no-cache',
        'authority': 'www.dongchedi.com',
        'referer': 'https://www.dongchedi.com/auto/series/1234',
    }
    rs = requests.get(url=url, headers=headers)
    tree = etree.HTML(rs.text)

    try:
        official_price = tree.xpath('//div[@data-row-anchor="official_price"]//div/text()')  # 官方价格
        sub_brand_name = tree.xpath('//div[@data-row-anchor="sub_brand_name"]//div/text()')  # 车商
        jb = tree.xpath('//div[@data-row-anchor="jb"]//div/text()')  # 级别
        fuel_form = tree.xpath('//div[@data-row-anchor="fuel_form"]//div/text()')  # 能源类型
        market_time = tree.xpath('//div[@data-row-anchor="market_time"]//div/text()')  # 上市时间
        engine_description = tree.xpath('//div[@data-row-anchor="engine_description"]//div/text()')  # 发动机
        energy_elect_max_power = tree.xpath('//div[@data-row-anchor="energy_elect_max_power"]//div/text()')  # 最大功率
        energy_elect_max_torque = tree.xpath('//div[@data-row-anchor="energy_elect_max_torque"]//div/text()')  # 最大扭矩
        gearbox_description = tree.xpath('//div[@data-row-anchor="gearbox_description"]//div/text()')  # 变速箱
        length_width_height = tree.xpath('//div[@data-row-anchor="length_width_height"]//div/text()')  # 长宽高
        car_body_struct = tree.xpath('//div[@data-row-anchor="car_body_struct"]//div/text()')  # 车身结构
        max_speed = tree.xpath('//div[@data-row-anchor="max_speed"]//div/text()')  # 最高时速
        acceleration_time = tree.xpath('//div[@data-row-anchor="acceleration_time"]//div/text()')  # 百公里加速时间
        wltc_fuel_comprehensive = tree.xpath('//div[@data-row-anchor="wltc_fuel_comprehensive"]//div/text()')  # WLTC综合油耗
        period = tree.xpath('//div[@data-row-anchor="period"]//div/text()')  # 保修期限
        maintain_cost = tree.xpath('//div[@data-row-anchor="maintain_cost"]//div/text()')  # 六万公里保养费用
    except:
        pass

    for i in range(len(official_price)):
        print(official_price[i], sub_brand_name[i], jb[i], fuel_form[i], market_time[i], engine_description[i],
              energy_elect_max_power[i], energy_elect_max_torque[i], gearbox_description[i], length_width_height[i],
              car_body_struct[i]
              )
